package com.jhgsys.internal.incentive.controller;

import com.jhgsys.internal.common.annotation.Log;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.incentive.entity.IncentiveRewardUser;
import com.jhgsys.internal.incentive.service.IIncentiveRewardUserService;
import com.wuwenze.poi.ExcelKit;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * 安全奖励人员 Controller
 *
 * @author wanghjw
 * @date 2024-09-03 14:08:31
 */
@Slf4j
@Validated
@Controller
public class IncentiveRewardUserController extends BaseController {

    @Autowired
    private IIncentiveRewardUserService incentiveRewardUserService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveRewardUser")
    @RequiresPermissions("incentiveRewardUser:view")
    public String incentiveRewardUserIndex(){
        return FebsUtil.view("incentive/incentiveRewardUser/incentiveRewardUserList");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveRewardUser/add")
    @RequiresPermissions("incentiveRewardUser:add")
    public String incentiveRewardUserAdd(){
        return FebsUtil.view("incentive/incentiveRewardUser/incentiveRewardUserEdit");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveRewardUser/update/{id}")
    @RequiresPermissions("incentiveRewardUser:edit")
    public String incentiveRewardUserUpdate(Model model, @PathVariable("id") String id){
        model.addAttribute("incentiveRewardUser", incentiveRewardUserService.findIncentiveRewardUserById(id));
        return FebsUtil.view("incentive/incentiveRewardUser/incentiveRewardUserEdit");
    }

    /**
     * 查询（所有）
     * @author wanghjw
     * @date 2024-09-03 14:08:31
     */
    @GetMapping("incentiveRewardUser")
    @ResponseBody
    @RequiresPermissions("incentiveRewardUser:view")
    public FebsResponse getAllIncentiveRewardUsers(IncentiveRewardUser incentiveRewardUser) {
        return new FebsResponse().success().data(incentiveRewardUserService.findIncentiveRewardUserList(incentiveRewardUser));
    }

    /**
     * 查询（分页）
     * @author wanghjw
     * @date 2024-09-03 14:08:31
     */
    @GetMapping("incentiveRewardUser/list")
    @ResponseBody
    @RequiresPermissions("incentiveRewardUser:view")
    public FebsResponse incentiveRewardUserList(QueryRequest request, IncentiveRewardUser incentiveRewardUser) {
        Map<String, Object> dataTable = getDataTable(this.incentiveRewardUserService.findIncentiveRewardUserPage(request, incentiveRewardUser));
        return new FebsResponse().success().data(dataTable);
    }

    /**
     * 新增 IncentiveRewardUser
     * @author wanghjw
     * @date 2024-09-03 14:08:31
     */
    @Log("新增IncentiveRewardUser")
    @PostMapping("incentiveRewardUser")
    @ResponseBody
    @RequiresPermissions("incentiveRewardUser:add")
    public FebsResponse addIncentiveRewardUser(@Valid IncentiveRewardUser incentiveRewardUser) throws FebsException {
        try {
            incentiveRewardUser.setCreatedBy(getCurrentUser().getUserName());
            this.incentiveRewardUserService.createIncentiveRewardUser(incentiveRewardUser);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "新增IncentiveRewardUser失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
     * 逻辑删除 IncentiveRewardUser
     * @author wanghjw
     * @date 2024-09-03 14:08:31
     */
    @Log("逻辑删除IncentiveRewardUser")
    @GetMapping("incentiveRewardUser/delete/{id}")
    @ResponseBody
    @RequiresPermissions("incentiveRewardUser:delete")
    public FebsResponse deleteIncentiveRewardUser(@PathVariable("id") String incentiveRewardUserIds) throws FebsException {
        try {
            IncentiveRewardUser incentiveRewardUser = new IncentiveRewardUser();
            incentiveRewardUser.setDeletedBy(getCurrentUser().getUserName());
            incentiveRewardUser.setDeletedTime(new Date());
            incentiveRewardUser.setDeletedFlg(FebsConstant.INVALID);
            this.incentiveRewardUserService.deleteIncentiveRewardUser(incentiveRewardUser,incentiveRewardUserIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除IncentiveRewardUser失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
    * 物理删除 IncentiveRewardUser
    * @author wanghjw
    * @date 2024-09-03 14:08:31
    */
    @Log("物理删除IncentiveRewardUser")
    @GetMapping("incentiveRewardUser/physicallyDelete/{id}")
    @ResponseBody
    @RequiresPermissions("incentiveRewardUser:delete")
    public FebsResponse physicallyDeleteIncentiveRewardUser(@PathVariable("id") String incentiveRewardUserIds) throws FebsException {
        try {
            this.incentiveRewardUserService.physicallyDeleteIncentiveRewardUser(incentiveRewardUserIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除IncentiveRewardUser失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
     * 修改 IncentiveRewardUser
     * @author wanghjw
     * @date 2024-09-03 14:08:31
     */
    @Log("修改IncentiveRewardUser")
    @PostMapping("incentiveRewardUser/update")
    @ResponseBody
    @RequiresPermissions("incentiveRewardUser:edit")
    public FebsResponse updateIncentiveRewardUser(IncentiveRewardUser incentiveRewardUser) throws FebsException {
        try {
            incentiveRewardUser.setUpdatedBy(getCurrentUser().getUserName());
            this.incentiveRewardUserService.updateIncentiveRewardUser(incentiveRewardUser);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "修改IncentiveRewardUser失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

}
